package com.LC.Controller.BKManagement;

import com.LC.Constant.MessageConstant;
import com.LC.Entity.Order;
import com.LC.Entity.PageResult;
import com.LC.Entity.QueryPageBean;
import com.LC.Entity.Result;
import com.LC.Service.OrderService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class OrderController {
    
    @Reference
    OrderService orderService;
    
    @PostMapping("/Order/Page")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = null;
        try {
            pageResult = orderService.findPage(queryPageBean);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageResult;
    }
    
    @PostMapping("/BKOrder")
    public Result addOrderFromBackend(@RequestBody Map map){
        map.put("telephone",map.get("phoneNumber"));
        map.put("name",map.get("memberName"));
        map.put("sex",map.get("gender"));
        Result result = null;
        try {
            result = orderService.NewOrder(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    
    @GetMapping("/BKOrder/{id}")
    public Result getDataByRowId(@PathVariable int id){
        Order order = null;
        try {
            order = orderService.GetOrderById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_ORDER_FAIL);
        }
        return new Result(true,MessageConstant.QUERY_ORDER_SUCCESS,order);
    }
    
    @PutMapping("/BKOrder")
    public Result EditOrderFromBackend(){
        
        return null;
    }
    
}
